package com.hq.service.impl;

import com.hq.mapper.RoleLoginMapper;
import com.hq.pojo.RoleLogin;
import com.hq.service.RoleLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class RoleLoginServiceImpl implements RoleLoginService {
    @Autowired
    private RoleLoginMapper roleLoginMapper;

    @Override
    public Map<String, String> roleLogin(RoleLogin roleLogin) {
        RoleLogin roleLogins = roleLoginMapper.roleLogin (roleLogin);
        Map<String, String> map = new HashMap<>();

        if (roleLogin == null){
            map.put ("loginInfo","该用户账号或者密码错误");
            map.put ("code","201");
            return map;
        }else {
            map.put ("loginInfo","用户存在");
            map.put ("code",roleLogins.getRole ());
            return map;
        }
    }

    @Override
    public Map<String, String> roleSignIn(RoleLogin roleLogins) {
        RoleLogin roleLogin = roleLoginMapper.ifRoles (roleLogins.getUsername ());
        Map<String, String> map = new HashMap<>();
        if (roleLogin==null){
            map.put ("code","succeed");
            roleLoginMapper.roleSignIn (roleLogins);
            if (roleLogins.getRole ().equals ("医生")){
                roleLoginMapper.insertDoctor (roleLogins.getUsername ());
                map.put ("role","医生");
            }
            return map;
        }else {
            map.put ("code","error");
            return map;
        }
    }
}
